package com.zc.custom.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zc.custom.domain.ChargeCustomUser;
import com.zc.custom.service.IChargeCustomUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户Controller
 * 
 * @author glb
 * @date 2023-05-19
 */
@RestController
@RequestMapping("/custom/user")
public class ChargeCustomUserController extends BaseController
{
    @Autowired
    private IChargeCustomUserService chargeCustomUserService;

    /**
     * 查询客户列表
     */
    @PreAuthorize("@ss.hasPermi('custom:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChargeCustomUser chargeCustomUser)
    {
        startPage();
        List<ChargeCustomUser> list = chargeCustomUserService.selectChargeCustomUserList(chargeCustomUser);
        return getDataTable(list);
    }

    /**
     * 导出客户列表
     */
    @PreAuthorize("@ss.hasPermi('custom:user:export')")
    @Log(title = "客户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChargeCustomUser chargeCustomUser)
    {
        List<ChargeCustomUser> list = chargeCustomUserService.selectChargeCustomUserList(chargeCustomUser);
        ExcelUtil<ChargeCustomUser> util = new ExcelUtil<>(ChargeCustomUser.class);
        util.exportExcel(response, list, "客户数据");
    }

    /**
     * 获取客户详细信息
     */
    @PreAuthorize("@ss.hasPermi('custom:user:query')")
    @GetMapping(value = "/{customId}")
    public AjaxResult getInfo(@PathVariable("customId") Long customId)
    {
        return AjaxResult.success(chargeCustomUserService.selectChargeCustomUserByCustomId(customId));
    }

    /**
     * 新增客户
     */
    @PreAuthorize("@ss.hasPermi('custom:user:add')")
    @Log(title = "客户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChargeCustomUser chargeCustomUser)
    {
        return toAjax(chargeCustomUserService.insertChargeCustomUser(chargeCustomUser));
    }

    /**
     * 修改客户
     */
    @PreAuthorize("@ss.hasPermi('custom:user:edit')")
    @Log(title = "客户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChargeCustomUser chargeCustomUser)
    {
        return toAjax(chargeCustomUserService.updateChargeCustomUser(chargeCustomUser));
    }

    /**
     * 删除客户
     */
    @PreAuthorize("@ss.hasPermi('custom:user:remove')")
    @Log(title = "客户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customIds}")
    public AjaxResult remove(@PathVariable Long[] customIds)
    {
        return toAjax(chargeCustomUserService.deleteChargeCustomUserByCustomIds(customIds));
    }
}
